const app = getApp();
const utils = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    staffCount: 0,
    userCount: 0,
    localStaffCount: 0,
    localUserCount: 0,
    regionId: 0,
    layer: 3,
    city: ''
  },

  getTotalData: function (regionid=0) {
    let that = this;
    wx.request({
      url: app.globalData.host + '/api/wxstore/CardReport?parentUid='+ app.globalData.userInfo.Uid +'&regionId=' + regionid+'&layer=' + that.data.layer,
      success: function (res) {
        if (res.data.Code == 0) {
          if (res.data.Data) {
            that.setData({
              staffCount: res.data.Data.StaffCount,
              userCount: res.data.Data.UserCount,
              localStaffCount: res.data.Data.LocalStaffCount,
              localUserCount: res.data.Data.LocalUserCount
            })
          }
        }
      },
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getLocation();
    
  },
  // 获取地理位置
  getLocation: function () {
    let that = this;
    utils.getLocation((location)=>{
     that.getCurrentCity(location.lat, location.lng);
    },app);   
  },
  getCurrentCity: function (lat, log) {
    let that = this;
    wx.request({
      url: app.globalData.host + '/api/Tool/GetRegionByGeo?lat=' + lat + '&lng=' + log,
      success: function (res) {
        if (res.data.Code == 0) {
          that.getTotalData(res.data.Data.RegionId);
          let name = '';
          if(res.data.Data.CityName){
            name = res.data.Data.CityName + res.data.Data.Name
          }
          that.setData({
            city: name,
            regionId: res.data.Data.RegionId,
            layer: res.data.Data.Layer
          })
        } 
      }
    })
  },

  toMerList: function () {
    wx.navigateTo({
      url: '../settledBusiness/index?regionId=' + this.data.regionId,
    })
  },

  toMember: function () {
    wx.navigateTo({
      url: '../jjCardMember/index?regionId=' + this.data.regionId,
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  }
})